package com.arellomobile.android.push;

import android.content.Context;
import android.util.Log;
import com.arellomobile.android.push.request.RequestHelper;
import com.arellomobile.android.push.utils.NetworkUtils;
import com.arellomobile.android.push.utils.NetworkUtils.NetworkResult;
import com.arellomobile.android.push.utils.PreferenceUtils;
import com.google.android.gcm.GCMRegistrar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class DeviceRegistrar
{
  private static final String REGISTER_PATH = "registerDevice";
  private static final String TAG = "DeviceRegistrar";
  private static final String UNREGISTER_PATH = "unregisterDevice";

  private static NetworkUtils.NetworkResult makeRequest(Context paramContext, String paramString1, String paramString2)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    localHashMap.putAll(RequestHelper.getRegistrationUnregistrationData(paramContext, paramString1, "1.3"));
    return NetworkUtils.makeRequest(localHashMap, paramString2);
  }

  static void registerWithServer(Context paramContext, String paramString)
  {
    Log.w("DeviceRegistrar", "Try To Registered for pushes");
    NetworkUtils.NetworkResult localNetworkResult = null;
    Object localObject = new Exception();
    label205: for (int i = 0; ; i++)
    {
      if (i >= 5);
      while (true)
        if (((Exception)localObject).getMessage() != null)
        {
          PushEventsTransmitter.onRegisterError(paramContext, ((Exception)localObject).getMessage());
          Log.e("DeviceRegistrar", "Registration error " + ((Exception)localObject).getMessage(), (Throwable)localObject);
          return;
          try
          {
            localNetworkResult = makeRequest(paramContext, paramString, "registerDevice");
            if (200 != localNetworkResult.getResultCode())
              break label205;
            if (200 == localNetworkResult.getPushwooshCode())
            {
              GCMRegistrar.setRegisteredOnServer(paramContext, true);
              PushEventsTransmitter.onRegistered(paramContext, paramString);
              PreferenceUtils.setLastRegistration(paramContext, new Date().getTime());
              Log.w("DeviceRegistrar", "Registered for pushes: " + paramString);
              return;
            }
          }
          catch (Exception localException)
          {
            localObject = localException;
          }
        }
      String str = localNetworkResult.getResultData().toString();
      Log.e("DeviceRegistrar", "Registration error " + str);
      PushEventsTransmitter.onRegisterError(paramContext, localNetworkResult.getResultData().toString());
      return;
    }
  }

  static void unregisterWithServer(Context paramContext, String paramString)
  {
    Log.w("DeviceRegistrar", "Try To Unregistered for pushes");
    GCMRegistrar.setRegisteredOnServer(paramContext, false);
    NetworkUtils.NetworkResult localNetworkResult = null;
    Object localObject = new Exception();
    label195: for (int i = 0; ; i++)
    {
      if (i >= 5);
      while (true)
        if (((Exception)localObject).getMessage() != null)
        {
          PushEventsTransmitter.onUnregisteredError(paramContext, ((Exception)localObject).getMessage());
          Log.e("DeviceRegistrar", "Unregistration error " + ((Exception)localObject).getMessage(), (Throwable)localObject);
          return;
          try
          {
            localNetworkResult = makeRequest(paramContext, paramString, "unregisterDevice");
            if (200 != localNetworkResult.getResultCode())
              break label195;
            if (200 == localNetworkResult.getPushwooshCode())
            {
              PushEventsTransmitter.onUnregistered(paramContext, paramString);
              Log.w("DeviceRegistrar", "Unregistered for pushes: " + paramString);
              PreferenceUtils.resetLastRegistration(paramContext);
              return;
            }
          }
          catch (Exception localException)
          {
            localObject = localException;
          }
        }
      String str = localNetworkResult.getResultData().toString();
      Log.e("DeviceRegistrar", "Unregistration error " + str);
      PushEventsTransmitter.onUnregisteredError(paramContext, localNetworkResult.getResultData().toString());
      return;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.arellomobile.android.push.DeviceRegistrar
 * JD-Core Version:    0.6.2
 */